/*
 * SensorPoller.hpp
 *
 *  Created on: 4 dec. 2012
 *      Author: Admin
 */

#ifndef SENSORPOLLER_HPP_
#define SENSORPOLLER_HPP_

#include "LaneSensorPoller.hpp"
#include "Sensor.hpp"
#include "Side.hpp"

/**
 * This class polls all sensors and parses the data.
 */
class SensorPoller
{
public:
	/**
	 * Constructs instance with a sensorCount of 0.
	 * @see sensorCount
	 */
	SensorPoller();
	virtual ~SensorPoller();

	/**
	 * Goes through all sensors in the sensors array, and polls them.
	 *
	 * @see pllCollisionSensor()
	 * @see pollColorLaneSensor()
	 * @see pollCrossRoadsSensor()
	 * @see pollDistanceSensor()
	 * @see pollEmergencyStopSensor()
	 * @see sensors
	 */
	void poll();

	/**
	 * Adds a sensor to the sensors array.
	 *
	 * @see sensors
	 *
	 * @param sensor pointer to the sensor that's to be added.
	 */
	void addSensor(Sensor* sensor);

	/**
	 * Adds a sensor to the sensors array.
	 *
	 * @see sensors
	 *
	 * @param sensor reference to the sensor that's to be added.
	 */
	void addSensor(Sensor& sensor);
private:
	/**
	 * Array containing pointers to all sensors added to the class.
	 */
	Sensor* sensors[10];
	/**
	 * Array containing the values the sensors had the previous polling.
	 */
	bool lastValues[10];
	/**
	 * Count of the amount of sensors currently added to the class.
	 */
	short sensorCount;

	/**
	 * Parses the collision sensor's poll.
	 * Detects whether the robot has collided, and sends an event if it has.
	 *
	 * @see Side.hpp
	 *
	 * @param side the side of the robot the collision sensor is connected to.
	 * @param lastValue the value the sensor had in the previous polling
	 * @param newValue the value the sensor has right now.
	 */
	void pollCollisionSensor(Side side, bool lastValue, bool newValue);

	/**
	 * Parses the crossroads sensor's poll.
	 * Detects if the robot is on a crossroads, sends an event if it is.
	 *
	 * @param lastValue the value the sensor had in the previous polling
	 * @param newValue the value the sensor has right now.
	 */
	void pollCrossRoadsSensor(bool lastValue, bool newValue);

	/**
	 * Parses the distance sensor's poll.
	 * Detects if the distance sensor sees an object.
	 *
	 * @param lastValue the value the sensor had in the previous polling
	 * @param newValue the value the sensor has right now.
	 */
	void pollDistanceSensor(bool lastValue, bool newValue);

};

#endif /* SENSORPOLLER_HPP_ */
